module('lgx.decls.class', package.seeall)
local decl = require'lgx.decl'
local mt = decl.new()
mt.__index = mt

function new(o)
    o          = decl.new(o)
    o.tag      = decl.CLASS
    o.baselist = {}
    o.opfuncs  = {}
    setmetatable(o, mt)
    return o
end

function mt:haveopfunc(decl)
    for i,v in ipairs(self.opfuncs) do
        if v.id == decl.id then
            return true
        end
    end
    return false
end

function mt:getmember(attrtab)
    local mlist = self:idlist('members')
    for i,v in ipairs(mlist) do
        local found = true
        for k,v in pairs(attrtab) do
            if v[k] ~= v then
                found = false
                break
            end
        end
        if found then return v end
    end
    return nil
end

function mt:addsub(tag, sub)
    if tag == decl.BASE then
        table.insert(self.baselist, sub)
	elseif tag == decl.OPFUNC then
        if not self:haveopfunc(sub) then
            table.insert(self.opfuncs, sub)
        end
--    elseif tag == decl.VAR then
--        self.vars:insert(sub)
--	elseif tag == decl.CTOR then
--		self.ctors:insert(sub)
--	elseif tag == decl.DTOR then
--		assert(self.dtor == nil, 'can not have two dtors!')
--		self.dtor = sub
    end
end

